<?php

namespace App\Http\Requests;
/**
 * 表单验证
 * Class PermissionSaveRequest
 * @package App\Http\Requests
 */
class PermissionSaveRequest extends BaseRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->get('id', 0);
        $rules = [
            'name' => [
                'required',
                'between:2,20'
            ]
        ];
        if (!$id) {
            $rules = [
                'action' => [
                    'required'
                ]
            ];
        }
        return $rules;
    }

    public function messages()
    {
        return [
            'name.required' => '请输入名称',
            'action.required' => '请选择操作',
            'name.between' => '名称字符长度:min-:max'
        ];
    }
}
